// mircoApp/numberCollection/comm/exchangePopup/exchangePopup.js
const app = getApp();
Component({
  /**
   * 组件的属性列表
   */
  options: {  //小程序获取外部样式
    addGlobalClass: true,
  },
  properties: {
    changeShow: Boolean,
    addressName:String,
    maxtotal:Number,
    exParams:Object
  },

  /**
   * 组件的初始数据
   */
  data: {
    streetShow:false,
    addressShow:false,
    strShow:false,
    districtVal:[],
    is_region:'',
    region_hide:''
  },

  /**
   * 组件的方法列表
   */
  methods: {
    changeClose() {
      this.setData({
        changeShow:false,
      })
    },
    inputChnage(event) {
      let type = event.currentTarget.dataset.type;
      this.triggerEvent('inputChnage',{type:type,value:event.detail});
    },
    exchangeClick() {
      this.triggerEvent('exchangeClick');
    },
    exChange(event) {
      this.triggerEvent('examount',{value:event.detail});
    },
    onClickLeft() {
      this.setData({
        streetShow: false
      });
    },
    adressClick() {
      this.setData({
        addressShow:true
      });
    },
    getIsOpenAddress() {
      var that = this;
      let urlStr = app.getNetAddresss("member.member-address.is-region");
      app._getNetWork({
        url: urlStr,
        success: function (resdata) {
          var res = resdata.data;
          if (res.result == 1 && !app._isTextEmpty(res.data)) {
            that.setData({
              is_region: res.data.is_region
            });
          } else {
            console.log(res.msg);
          }
        },
        fail: function (res) {
          console.log(res);
        }
      });
    },
    areaConfirm(e){
      this.setData({
        strShow:true
      })
      this.getStreet(e.detail[2].id);
      this.triggerEvent('areaConfirm', e.detail);
    },
    streetClick() {
      this.setData({
        streetShow:true
      })
    },
    streetConfirm(event) {
      let item = event.currentTarget.dataset.item;
      this.setData({
        streetShow:false
      })
      this.triggerEvent('streetConfirm', item);
    },
    //获取街道
    getStreet(param) {
      let that = this;
      let urlStr = "";
      urlStr += app.getNetAddresss("member.memberAddress.street");
      urlStr += '&district_id=' + param;
      app._getNetWork({
        url: urlStr,
        success: function (resdata) {
          var res = resdata.data;
          if (res.result == 1) {
            if (!app._isTextEmpty(res.data) && res.data.length > 0) {
              that.setData({
                districtVal: res.data,
                strShow: true,
              });
            } else {
              that.setData({
                strShow: false
              });
            }
          } else {
            that.setData({
              strShow: false
            });
          }
        },
        fail: function (res) {
          console.log(res);
        }
      });
    },
  }
})
